#Programming #Python #pythonproject
Christmas Tree Python Program Project for Beginners!
This script prints a simple ASCII Christmas tree made of stars (*) and a trunk made of vertical bars (|). The Code is below:
# ---------------------------------------------
# Christmas Tree Program in Python
# This script prints a simple ASCII Christmas tree
# made of stars (*) and a trunk made of vertical bars (|).
# ---------------------------------------------
# Set the height of the tree (number of star layers)
height = 10 # You can change this to make the tree taller or shorter
# -----------------------------
# Build the leafy part of the tree
# -----------------------------
for i in range(height):
# Number of spaces before the stars (centers the tree)
spaces = ' ' * (height - i - 1)
# Number of stars for this row (odd numbers: 1, 3, 5, ...)
stars = '*' * (2 * i + 1)
# Print one row of the tree
print(spaces + stars)
# -----------------------------
# Build the trunk of the tree
# -----------------------------
trunk_width = 3 # Width of the trunk (number of | characters)
trunk_height = 3 # Height of the trunk (number of rows)
# Center the trunk under the tree
trunk_spaces = ' ' * (height - trunk_width // 2 - 1) #Produce a string of n spaces where n is (height - trunk_width // 2 - 1). Note '//' is integer division (e.g. 5 // 2 = 2 and not 2.5)
for _ in range(trunk_height):
print(trunk_spaces + '|' * trunk_width)
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
|
✅ Subscribe to our Channel to learn more...
🔥Microsoft AI Engineer Program - 🔥Part...
🔥Generative AI, Machine Learning, And In...
🔥Applied Generative AI Specialization - ...
Are you ready to dive into the world of ...
When researching online programs, many p...
AWS and Cerebras announced a collaborati...
Discover how Audi AG worked with AWS to ...
Storyblok delivers modern digital experi...
Jetpack Compose Glimmer is here to help ...
In Episode 1 of this 4-part series, @ama...
🔥Integrated MS+PGP Program in Data Scien...
BMW Group's Design and Virtual Product E...
LLMs alone can't deliver relevant custom...
PyCon JP Associationが主催するYouTubeライブです。実験...